import request from '@/utils/request'
import { praseStrEmpty } from '@/utils/ruoyi'

/** get请求校验拼接参数是否为空 */

/** 获取数据源列表 */
export function getDatasource() {
  return request({
    url: '/datasourceQuery/getDatasource',
    method: 'get'
  })
}

// 根据主题id查询指标表
export function getDefineByTheme(query) {
  return request({
    url: '/quotaDefine/getByTheme',
    method: 'get',
    params: query
  })
}

// 根据id查询指标来源表
export function getQuerySource(query) {
  return request({
    url: '/quotaDefine/querySource',
    method: 'get',
    params: query
  })
}

/** 获取指标列表 */
export function getDefineList(query) {
  console.log(query)
  return request({
    url: '/quotaDefine/getList',
    method: 'get',
    params: query
  })
}

/** 根据数据源ID获取数据 */
export function getTableAliasEnable(query) {
  console.log(query)
  return request({
    url: '/tableAlias/bySourceEnable',
    method: 'get',
    params: query
  })
}

/** 根据数据表别名ID获取字段别名记录 */
export function getColAlias(query) {
  return request({
    url: '/colAlias/byTable',
    method: 'get',
    params: query
  })
}

/** 根据ID获取指标数据 */
export function selectQuota(query) {
  return request({
    url: '/quotaDefine/selectQuota',
    method: 'get',
    params: query
  })
}

//存储指标数据
export function saveQuota(data) {
  return request({
    url: '/quotaDefine/createQuota',
    method: 'post',
    data: data
  })
}
//报表生成指标
export function getQuotaReportValue(data) {
  return request({
    url: '/quotaReport/computeValue',
    method: 'post',
    data: data
  })
}

//存储自定义指标数据
export function saveCustomQuota(data) {
  return request({
    url: '/quotaDefine/saveCustomQuota',
    method: 'post',
    data: data
  })
}

//存储数据库来源指标数据
export function addQuota(data) {
  return request({
    url: '/quotaDefine/saveQuota',
    method: 'post',
    data: data
  })
}

//存储维度数据
export function saveDimension(data) {
  return request({
    url: '/quotaDefine/createDimension',
    method: 'post',
    data: data
  })
}

// 根据指标id维度列表
export function queryDim(id) {
  return request({
    url: '/quotaDefine/queryDim/' + praseStrEmpty(id),
    method: 'get'
  })
}

// 根据id列表批量删除指标表
export function deleteQuota(ids) {
  return request({
    url: '/quotaDefine/deleteQuotaByids',
    method: 'delete',
    data: ids
  })
}

//插入维度与指标关系表
export function insertRelation(data) {
  return request({
    url: 'quotaDefine/insertRelation',
    method: 'post',
    data: data
  })
}

//插入维度与指标关系表
export function quotaModeling(data) {
  return request({
    url: '/quotaDefine/quotaModeling',
    method: 'post',
    data: data
  })
}

//插入指标值表
export function insertValue(data) {
  return request({
    url: '/quotaDefine/insertValue',
    method: 'post',
    data: data
  })
}

// 查询指标类型
export function queryQuotaType() {
  return request({
    url: '/quotaDefine/queryQuotaType',
    method: 'get'
  })
}

// 查询计算类型
export function queryComputeType() {
  return request({
    url: '/quotaDefine/queryComputeType ',
    method: 'get'
  })
}

// 查询指标类型列表
export function listDimension(query) {
  return request({
    url: '/quota/dimension/listBySearch',
    method: 'get',
    params: query
  })
}

//根据指标id查询指标信息和指标值
export function getQuotaAndValue(query) {
  return request({
    url: '/quotaDefine/getQuotaAndValue',
    method: 'post',
    data: query
  })
}

// 更新指标值
export function updateValue(data) {
  return request({
    url: '/quotaValue/updateValue',
    method: 'post',
    data: data
  })
}

export function injectQuotaValue(query) {
  return request({
    url: '/quotaValue/addQuotaValue',
    method: 'get',
    params: query
  })
}

export function listQuota(query) {
  return request({
    url: '/quotaDefine',
    method: 'get',
    params: query
  })
}

export function listQuotaValue(query) {
  return request({
    url: '/quotaValue',
    method: 'get',
    params: query
  })
}

//查询指标值数据 增加维度筛选
export function list(query) {
  return request({
    url: '/quotaValue/list',
    method: 'post',
    data: query
  })
}

//查看指标溯源
export function lookForSource(id) {
  return request({
    url: '/quotaDefine/lookForSource/' + praseStrEmpty(id),
    method: 'get'
  })
}

//查询所有的运算符
export function getAllFormulaOperator() {
  return request({
    url: '/formulaOperator/getAllFormulaOperator',
    method: 'get'
  })
}

//指标生成指标查询更具指标id查询指标关联的维度
export function quotaDimRelationDetail(id) {
  return request({
    url: '/quotaDimRelationDetail/' + praseStrEmpty(id),
    method: 'get'
  })
}

//指标生成指标提交数据
export function quotaGenerateQuota(data) {
  return request({
    url: '/quotaFormula/create',
    method: 'post',
    data: data
  })
}

//根据所选生成值类型指标生成指标
export function createQuotaByType(data) {
  return request({
    url: '/quotaFormula/createQuotaByType',
    method: 'post',
    data: data
  })
}

//查询多个指标的公共维度 子节点包含根节点id
export function getBeMixed(data) {
  return request({
    url: '/quotaDimRelationDetail/beMixed',
    method: 'post',
    data: data
  })
}

//可组装树公共维度
export function getBeMixedTree(data) {
  return request({
    url: '/quotaDimRelationDetail/getBeMixedTree',
    method: 'post',
    data: data
  })
}

//查询多个指标的公共维度 只有根节点
export function getBeMixedRoot(data) {
  return request({
    url: '/quotaDimRelationDetail/beMixedRoot',
    method: 'post',
    data: data
  })
}

export function getQuotaDetail(id) {
  return request({
    url: '/quotaDefine/getQuotaDetail/' + praseStrEmpty(id),
    method: 'get'
  })
}

export function getReportJson(data) {
  return request({
    url: '/quotaValue/getReportJson',
    method: 'post',
    data: data
  })
}

export function getBarChartsJson(data) {
  return request({
    url: '/quotaValue/getBarChartsJson',
    method: 'post',
    data: data
  })
}

export function getPieChartsJson(data) {
  return request({
    url: '/quotaValue/getPieChartsJson',
    method: 'post',
    data: data
  })
}
export function getScatterChartsJson(data) {
  return request({
    url: '/quotaValue/getScatterChartsJson',
    method: 'post',
    data: data
  })
}
